/*
 * A scrollbar with pastel Media Lab colors.
 * Look in License.m for example of use.
 * By Michael Hawley, with help from Bruce Blumberg.
 */
/*
    Copyright (c) 1991, 1992 by the MIT Media Laboratory
    
    This software is distributed by Michael Hawley of the MIT Media Laboratory. 
    We hope it will be useful to you.
    
    Permission to use, copy, or modify this software for educational 
    and research purposes only and without fee is hereby granted 
    provided this notice appears on all copies, and provided you send 
    us your improvements.  Any other use of this software, in original 
    or modified form, in whole or in part, requires specific permission 
    from MIT.  This software shall not be used, rewritten, or adapted 
    for use in a commercial product without first obtaining appropriate 
    licenses from MIT.  MIT makes no representations about the suitability 
    of this software for any purpose: it is provided "as is" without any 
    warranty and any risk, damage, or liability incurred through your use 
    of this software is yours alone.
    
    Michael Hawley
    MIT Media Laboratory
    20 Ames Street, 
    Cambridge, MA 02139
    mike@media-lab.mit.edu
*/

#import <appkit/appkit.h>
#import "ColorScroller.h"

#define N 8

static float pct[N] = {.0790, .1535, .0564, .2279, .0745, .2596, .1083, .0406};
static NXColor color[N];

static void
initColors(){
    int i = 0;
#define mix(a,b) (a-p*(a-b))
#define M(x) (170.0-0.3*(170-x))/256.0
#define C(r,g,b) color[i++] = NXConvertRGBToColor(M(r), M(g), M(b));
    C(77.0,17.0,93.0)
    C(0.0,85.0,0.0)
    C(255.0,255.0,255.0)
    C(210.0,0.0,0.0)
    C(255.0,90.0,0.0)
    C(0.0,0.0,151.0)
    C(255.0,248.0,0.0)
    C(85.0,85.0,85.0)
}

@implementation ColorScroller

-initFrame:(const NXRect *)r {
    [super initFrame:r];
    [self setEnabled:YES];
    [self setArrowsPosition:NX_SCROLLARROWSNONE];
    initColors();
    return self;
}

- drawBackground {
    NXRect r;
    int i;
    float h;
    
    [self calcRect:&r forPart:NX_KNOBSLOT];
    r.origin.x += 1; r.size.width -= 2;
    r.origin.y += 1; r.size.height -= 2;
    h = r.size.height;
    /* now r is the size that you can draw into */
    for(i=0;i<N;i++){
	r.size.height = h * pct[i];
	NXSetColor(color[i]);
	NXRectFill(&r);
	r.origin.y += r.size.height;
    }
    return self;
}

- drawKnob {
    [self drawBackground];
    [super drawKnob];
    return self;
}

@end
